package com.zjsru.oneDay202211;

/**
 * @Author: CookLee
 * @Date: 2022/11/8
 * 统计一致字符串的数目
 * 给你一个由不同字符组成的字符串 allowed 和一个字符串数组 words 。如果一个字符串的每一个字符都在 allowed 中，就称这个字符串是 一致字符串 。
 * 输入：allowed = "ab", words = ["ad","bd","aaab","baa","badab"]
 * 输出：2
 * 解释：字符串 "aaab" 和 "baa" 都是一致字符串，因为它们只包含字符 'a' 和 'b' 。
 *
 * 输入：allowed = "abc", words = ["a","b","c","ab","ac","bc","abc"]
 * 输出：7
 * 解释：所有字符串都是一致的。
 */
public class CountConsistentStrings {
    
    /**
     * 模拟 用位转存
     **/
    public int countConsistentStrings(String allowed, String[] words) {
        boolean[] hash = new boolean[26];
        for (char c : allowed.toCharArray()) {
            hash[c - 'a'] = true;
        }
        int ans = 0;
        out:
        for (String s : words) {
            for (char c : s.toCharArray()) {
                if (!hash[c - 'a']) {
                    continue out;
                }
            }
            ans++;
        }
        return ans;
    }
    
    public static void main(String[] args) {
        CountConsistentStrings countConsistentStrings = new CountConsistentStrings();
        String allowed = "abc";
        String[] words = new String[] {"a","b","c","ab","ac","bc","abc"};
        System.out.println(countConsistentStrings.countConsistentStrings(allowed, words));
    }
}
